package com.feng.seata.web;

import com.alibaba.nacos.api.model.v2.Result;
import com.feng.seata.model.UserEntity;
import com.feng.seata.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * @author yinglong.zhang
 * @description
 * @date 2024-1-26 17:52
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping
    public Result<Long> create(@RequestBody UserEntity user) {
        return Result.success(userService.addUser(user));
    }

    @PutMapping
    public Result<UserEntity> updateById(@RequestBody UserEntity user) {
        return null;
    }

    @DeleteMapping("{id}")
    public Result<UserEntity> removeById(@PathVariable Serializable id) {
        return null;
    }

    @GetMapping("{id}")
    public Result<UserEntity> getById(@PathVariable Serializable id) {
        return null;
    }

    @PostMapping("/score")
    public Result<Void> addScore(@RequestBody UserEntity userEntity) {
        userService.addScore(userEntity);
        return Result.success();
    }
}
